//
//  SC_Search_ResultModel.swift
//  APSwift
//
//  Created by jianbo.pei on 2023/4/26.
//

import HandyJSON

class SC_Search_ResultModel: HandyJSON {
    required init() {}
    var total: Int = 0
    var total_page: Int = 1
    var page: Int = 1
    var size: Int = 10
    var items: [SC_Search_ResultItemModel]?
}

class SC_Search_ResultItemModel: HandyJSON {
    required init() {}
    
    enum SearchType: String, HandyJSONEnum {
        case SINGLE_ROOM
        case MANY_PEOPLE_ROOM
        case DEFAULT_ROOM
        case FAMILY_USER
        case USER
        
        var cnName: String {
            get {
                switch self {
                case .SINGLE_ROOM:
                    /// 公会单人房
                    return "相关直播间"
                case .MANY_PEOPLE_ROOM:
                    /// 公会多人房
                    return "相关派对"
                case .DEFAULT_ROOM:
                    /// 连麦交友房
                    return "相关房间"
                case .FAMILY_USER:
                    return "相关主播"
                case .USER:
                    return "相关用户"
                }
            }
        }
    }
    var type: SearchType?
    var item_info: [String: Any]?
}

extension SC_Search_ResultItemModel {
    /// 获取真正的itemModel
    func itemInfoModel() -> APReuseView_M_Protocol? {
        guard let type = type, let item_info = item_info else { return nil }
        switch type {
        case .SINGLE_ROOM, .MANY_PEOPLE_ROOM, .DEFAULT_ROOM:
            guard var roomModel = SC_Search_RoomModel.deserialize(from: item_info) else { return nil }
            roomModel.type = type
            return roomModel
        case .FAMILY_USER, .USER:
            guard var userModel = SC_Search_UserModel.deserialize(from: item_info) else { return nil }
            userModel.type = type
            return userModel
        }
    }
}
